package fatworm.concept.datatype;
/**
 * string type, this type is just defined for computing
 * in FatWorm storage , string can be CHAR(M) or VARCHAR(M)
 */
public class FatString extends fatworm.concept.DataType{
	private static final FatString instance = new FatString();
	public static FatString getInstance(){
		return instance;
	}
	
	private FatString(){}
	public int getTypeKey() {
		return T_STRING;
	}
	/** create a new string value */
	public StringValue createValue( String s ){
		System.out.println(s);
		return new StringValue( s );
	}
	public StringValue convert( SqlValue value ) 
			throws ConvertException {
		switch( value.getType().getTypeKey() ){
			case T_STRING	: return (StringValue)value;
			case T_VARCHAR	:
			case T_CHAR  	: return new StringValue( value.toString() );
			default		 	: throw new ConvertException( value , this );
		}
	}
	public String toString() {
		return "STRING";
	}
	public class StringValue extends SqlValue{
		public String value;
		private StringValue( String value ){
			this.value = value;
		}
		
		public String toString() {
			return value;
		}
	}
}
